Skip to content

fix(ratewise): 為導覽 case-3 加上有界網路 fallback#426

Merged
s123104 merged 2 commits into
chore/ratewise-production-governancefrom
fix/sw-bounded-nav-fallback
Jun 26, 2026
Merged

fix(ratewise): 為導覽 case-3 加上有界網路 fallback#426
s123104 merged 2 commits into
chore/ratewise-production-governancefrom
fix/sw-bounded-nav-fallback

Conversation

@s123104

@s123104 s123104 commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

背景

PR #411 的 SW 導覽改為 precache-first 後,case 3(html-cache miss 且 matchPrecache('index.html') miss,例如 iOS precache 被驅逐)對 fetch無上限等待。在「已連線但掛住」的網路(TCP 連上、伺服器永不回應,如 captive portal)下,document 請求永不 resolve → 硬重載後無限白屏。離線(fetch throw)已能快速 fallback,純慢速網路也會在 1–3s 內送達 index.html,因此缺口只剩此 hung-network 案例。嚴重度 Low-Medium。

變更

apps/ratewise/src/sw.ts僅 case 3

  • 新增 NAVIGATION_FETCH_TIMEOUT_MS = 8000
  • Promise.race 為網路 fetch 設 8s 上限;逾時改回傳 resolveNavigationFallback()
  • 逾時時以 event.waitUntil(networkFetch…) 保留 in-flight fetch,網路稍後成功仍寫入 html-cache 供下次導覽

為何安全(不會重蹈 #411 修掉的假離線)

#411 移除舊 3s timeout,是因為它可能在 precache 仍存在時把 offline.html 誤送給在線用戶。本分支的 timeout 位於 precache 已確認不存在的 case 3,因此 timeout→offline fallback 結構上不可能造成假離線。Case 1(暖快取)與 case 2(precache 命中)完全未動,維持零延遲。

測試

apps/ratewise/src/__tests__/sw.test.ts 新增 handleNavigationRequest 行為測試:

  • case 2:precache 命中,fake timers 下無需推進 8s 即立即回傳 precached shell
  • case 3:fetch 永不 resolve,推進 8000ms 後回傳 offline fallback
  • 防回歸:仍禁止舊 NAVIGATION_NETWORK_TIMEOUT_MS 全域 timeout,允許新的 case-3-only NAVIGATION_FETCH_TIMEOUT_MS

驗證

  • pnpm --filter @app/ratewise typecheck
  • vitest run src/__tests__/sw.test.ts 37/37 綠
  • 既有離線 e2e(offline-cold-start / offline-pwa)未改動

patch changeset 已加入(使用者可見:離線/弱網下載入更穩定,不再可能卡白屏)。

🤖 Generated with Claude Code

- precache 已驅逐時等網路設 8s 上限,避免連線掛住造成無限白屏
- timeout 後以 event.waitUntil 保留 in-flight fetch,成功仍寫入 html-cache
- case 1 暖快取與 case 2 precache 命中維持零延遲不變
- 新增 handleNavigationRequest 單元測試覆蓋 case 2 即時與 case 3 逾時 fallback
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 508db98770

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .changeset/ratewise-sw-bounded-nav.md
- 將 matchPrecache mock 由 async 改為回傳 Promise.resolve,消除無 await 的 async
- 不影響 case-2/case-3 測試行為

測試:vitest run src/__tests__/sw.test.ts 37/37 通過;eslint 該檔 0 錯誤
@github-actions

Copy link
Copy Markdown
Contributor

✅ SEO 審計通過!所有 2026 標準驗證項目都符合要求。

  • ✅ Sitemap 2026 標準
  • ✅ Breadcrumb Schema
  • ✅ JSON-LD 結構化數據
  • ✅ 內部連結結構

@s123104 s123104 merged commit a9eae3d into chore/ratewise-production-governance Jun 26, 2026
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant